package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyCyhActivityVipMapper;
import com.laowang.project.system.domain.MyCyhActivityVip;
import com.laowang.project.system.service.MyCyhActivityVipService;

/**
 * 活动vip返佣Service业务层处理
 *
 * @author laowang
 * @date 2023-06-07
 */
@Service
public class MyCyhActivityVipServiceImpl implements MyCyhActivityVipService {
    @Autowired
    private MyCyhActivityVipMapper myCyhActivityVipMapper;

    /**
     * 查询活动vip返佣
     *
     * @param id 活动vip返佣ID
     * @return 活动vip返佣
     */
    @Override
    public MyCyhActivityVip selectMyCyhActivityVipById(Integer id) {
        return myCyhActivityVipMapper.selectMyCyhActivityVipById(id);
    }

    /**
     * 查询活动vip返佣列表
     *
     * @param myCyhActivityVip 活动vip返佣
     * @return 活动vip返佣
     */
    @Override
    public List<MyCyhActivityVip> selectMyCyhActivityVipList(MyCyhActivityVip myCyhActivityVip) {
        return myCyhActivityVipMapper.selectMyCyhActivityVipList(myCyhActivityVip);
    }

    /**
     * 新增活动vip返佣
     *
     * @param myCyhActivityVip 活动vip返佣
     * @return 结果
     */
    @Override
    public int insertMyCyhActivityVip(MyCyhActivityVip myCyhActivityVip) {
        Integer activityId = myCyhActivityVip.getActivityId();
        Integer vipLevel = myCyhActivityVip.getVipLevel();
        if (activityId == null || vipLevel == null){
            throw new CustomException("活动或者vip等级为空",400);
        }
        MyCyhActivityVip myCyhActivityVip1 = new MyCyhActivityVip();
        myCyhActivityVip1.setActivityId(activityId);
        myCyhActivityVip1.setVipLevel(vipLevel);
        List<MyCyhActivityVip> myCyhActivityVips = selectMyCyhActivityVipList(myCyhActivityVip1);
        if (myCyhActivityVips.size()>0){
            throw new CustomException("已经有该会员活动佣金了");
        }
        return myCyhActivityVipMapper.insertMyCyhActivityVip(myCyhActivityVip);
    }

    /**
     * 修改活动vip返佣
     *
     * @param myCyhActivityVip 活动vip返佣
     * @return 结果
     */
    @Override
    public int updateMyCyhActivityVip(MyCyhActivityVip myCyhActivityVip) {
        return myCyhActivityVipMapper.updateMyCyhActivityVip(myCyhActivityVip);
    }

    /**
     * 批量删除活动vip返佣
     *
     * @param ids 需要删除的活动vip返佣ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhActivityVipByIds(Integer[] ids) {
        return myCyhActivityVipMapper.deleteMyCyhActivityVipByIds(ids);
    }

    /**
     * 删除活动vip返佣信息
     *
     * @param id 活动vip返佣ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhActivityVipById(Integer id) {
        return myCyhActivityVipMapper.deleteMyCyhActivityVipById(id);
    }

    @Override
    public MyCyhActivityVip selectByActiIdAndVipLevel(Integer actiId, Integer vipLevel) {
        return myCyhActivityVipMapper.selectByActiIdAndVipLevel(actiId,vipLevel);
    }
}
